home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libspool / settings.c.z / settings.c
Encoding:
C/C++ Source or Header  |  1996-05-07  |  6.1 KB  |  209 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *           Copyright (c)    1991 Silicon Graphics, Inc.          *
  4.  *            All Rights Reserved                    *
  5.  *                                      *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI          *
  7.  *                                      *
  8.  * The copyright notice above does not evidence any actual of intended      *
  9.  * publication of such source code, and is an unpublished work by Silicon *
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or      *
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly *
  13.  * prohibited.                                  *
  14.  *                                      *
  15.  * RESTRICTED RIGHTS LEGEND:                          *
  16.  *                                      *
  17.  * Use, duplication or disclosure by the Government is subject to      *
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in      *
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR      *
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.      *
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311              *
  24.  **************************************************************************
  25.  *
  26.  * File: settings.c
  27.  *
  28.  * Description: Displays the job and printer options for the specified
  29.  *    printer.
  30.  *
  31.  **************************************************************************/
  32.  
  33.  
  34. #ident "$Revision: 1.3 $"
  35.  
  36.  
  37. #include <stdio.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #ifdef sgi
  41. #include <getopt.h>
  42. #endif
  43. #include "spool.h"
  44.  
  45.  
  46. char *pname;
  47. int spooler = SL_SPOOLER_NONE;        /* Indicate that no spooler is set */
  48. int not_sysv = 0;
  49.  
  50.  
  51. extern char *optarg;
  52. extern int optind;
  53.  
  54.  
  55. void disp_settings(SLSettingsStruct*, SLSysVSpoolerOptionsStruct*, char*);
  56. void usage(char*);
  57.  
  58.  
  59. main(int argc, char *argv[])
  60. {
  61.     int ch, ret;
  62.     int errflag = 0;
  63.     SLSettingsStruct *settings;            /* SLGetPrinterSettings(3) */
  64.     SLSysVSpoolerOptionsStruct *spooler_opts;    /* SLSysVGetSpoolerOptions(3) */
  65.     char *printer_opts;                /* SLSYSVGetPrinterOptions(3) */
  66.  
  67.     /*
  68.      * Process command line args
  69.      */
  70.     while ((ch = getopt(argc, argv, "s:")) != -1) {
  71.     switch (ch) {
  72.         case 's':        /* Spooler to use */
  73.         if (!strcmp(optarg, "bsd"))
  74.             spooler = SL_SPOOLER_BSD;
  75.         else if (!strcmp(optarg, "sysv"))
  76.             spooler = SL_SPOOLER_SYSV;
  77.         else
  78.             errflag++;
  79.         break;
  80.         case '?':
  81.         default:
  82.         errflag++;
  83.         break;
  84.     }
  85.     }
  86.  
  87.     /*
  88.      * If error, print usage and exit
  89.      */
  90.     if (errflag) {
  91.     usage(argv[0]);
  92.     exit(1);
  93.     }
  94.  
  95.     /*
  96.      * If a spooling system has been specified set it
  97.      */
  98.     if (spooler != SL_SPOOLER_NONE) {
  99.     if (SLSetSpooler(spooler) < 0) {
  100.         SLPerror(argv[0]);
  101.         exit(1);
  102.     }
  103.     }
  104.  
  105.     /*
  106.      * Get the printer name. If no printer name is specified, use
  107.      * the default printer
  108.      */
  109.     if (argc == optind) {
  110.     if (SLGetDefPrinterName(&pname) < 0) {
  111.         SLPerror(argv[0]);
  112.         exit(1);
  113.     }
  114.     } else
  115.     pname = argv[optind];
  116.  
  117.     /*
  118.      * Get the settings for this printer in a spooling
  119.      * system independent format.
  120.      */
  121.     if (SLGetPrinterSettings(pname, &settings) < 0) {
  122.         int j, status, nout;
  123.         char **out_buf;
  124.         SLPerror(argv[0]);
  125.         if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
  126.             (void)fprintf(stderr, "Spooler exit status: %d\n", status);
  127.             (void)fprintf(stderr, "Spooler error message(s):\n");
  128.             for (j = 0; j < nout; j++)
  129.                 (void)fprintf(stderr, "\t%s\n", out_buf[j]);
  130.         }
  131.         exit(1);
  132.     }
  133.  
  134.     /*
  135.      * Get the settings for this printer in a spooling
  136.      * system dependent format.
  137.      */
  138.     ret = SLSysVGetSpoolerOptions(&spooler_opts);
  139.     if (ret < 0 && SLerrno == SL_ERR_NO_SYSV)
  140.     not_sysv = 1;
  141.     else if (ret < 0) {
  142.         int j, status, nout;
  143.         char **out_buf;
  144.         SLPerror(argv[0]);
  145.         if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
  146.             (void)fprintf(stderr, "Spooler exit status: %d\n", status);
  147.             (void)fprintf(stderr, "Spooler error message(s):\n");
  148.             for (j = 0; j < nout; j++)
  149.                 (void)fprintf(stderr, "\t%s\n", out_buf[j]);
  150.         }
  151.         exit(1);
  152.     }
  153.     if (not_sysv == 0) {
  154.         if (SLSysVGetPrinterOptions(pname, &printer_opts) < 0) {
  155.             int j, status, nout;
  156.             char **out_buf;
  157.             SLPerror(argv[0]);
  158.             if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
  159.                 (void)fprintf(stderr, "Spooler exit status: %d\n", status);
  160.                 (void)fprintf(stderr, "Spooler error message(s):\n");
  161.                 for (j = 0; j < nout; j++)
  162.                     (void)fprintf(stderr, "\t%s\n", out_buf[j]);
  163.             }
  164.             exit(1);
  165.         }
  166.     }
  167.  
  168.     /*
  169.      * Show the settings information
  170.      */
  171.     disp_settings(settings, spooler_opts, printer_opts);
  172.  
  173.     return 0;
  174. }
  175.  
  176.  
  177. void disp_settings(SLSettingsStruct *gptr, SLSysVSpoolerOptionsStruct *sptr,
  178.                         char *pptr)
  179. {
  180.     (void)printf("Spooler independent settings for %s:\n", pname);
  181.     (void)printf("\tJob handling:\t\t%s\n", (gptr->copy) ? "copy": "link");
  182.     (void)printf("\tMail on completion:\t%s\n", (gptr->mail) ? "yes": "no");
  183.     (void)printf("\tBanner title:\t\t%s\n", (gptr->title) ?
  184.                     gptr->title: "[default]");
  185.     (void)printf("\tSpooler options:\t%s\n", (gptr->options) ?
  186.                     gptr->options: "[none]");
  187.  
  188.     if (not_sysv)
  189.     return;
  190.  
  191.     (void)printf("\n");
  192.     (void)printf("System V spooler settings for %s:\n", pname);
  193.     (void)printf("\tJob handling:\t\t%s\n", (sptr->copy) ? "copy": "link");
  194.     (void)printf("\tMail on completion:\t%s\n", (sptr->mail) ? "yes": "no");
  195.     (void)printf("\tMessage on completion:\t%s\n",
  196.                     (sptr->message) ? "yes": "no");
  197.     (void)printf("\tSuppress job ID:\t%s\n", (sptr->suppress_id) ? "yes": "no");
  198.     (void)printf("\tBanner title:\t\t%s\n", (sptr->title) ?
  199.                     sptr->title: "[default]");
  200.     (void)printf("\tPrinter options:\t%s\n", (pptr) ? pptr: "[none]");
  201. }
  202.  
  203.  
  204. void usage(char *progname)
  205. {
  206.     (void)fprintf(stderr, "%s [-s bsd | sysv] [printer_name]\n",
  207.                     progname);
  208. }
  209.